package com.xiongjie.ClusterCache.Interface.impl;

import com.xiongjie.ClusterCache.Interface.IClusterCache;
import com.xiongjie.ClusterCache.entity.ClusterCacheEntity;
import org.infinispan.Cache;

public abstract class IClusterCacheImpl implements IClusterCache {

    final private Cache<String, ClusterCacheEntity> cache;

    public IClusterCacheImpl(Cache<String, ClusterCacheEntity> cache) {
        this.cache = cache;
    }

    @Override
    final public ClusterCacheEntity getValueByName(String name) {
        ClusterCacheEntity entity = cache.get(name);
        if (entity == null) {
            entity = getClusterCacheEntity(name);
            cache.put(name, entity);
        }
        return entity;
    }

    protected abstract ClusterCacheEntity getClusterCacheEntity(String name);
}
